/**
   Counts the number of times a character appears in a string.
*/

public class CharCounter
{
   /**
      Returns the number of times that a target character
      appears in a string.
      @param source the input string
      @param ch the character to be counted (a string of length 1)
      @return the number of times the target character
      appears in the source
   */
   public static int countChar(String str, char ch)
   {
      int l = str.length(),k=0;
      for(int i=0;i<l;i++){
         char c = str.charAt(i);
         if(c==ch)
         k++;
      }
      return k;
   }
}